<template>
	<view class="app">
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>推广员ID</view>
					<view><input v-model="user_id" placeholder="请输入推广员ID" /></view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="query">查询</button>
				</view>
			</view>
		</view>
		
		<view class="panel">
			<view class="flex-col setpidpage">
				<view class="flex justify-between inputitem">
					<view>真实姓名</view>
					<view><input v-model="realname" placeholder="请输入真实姓名" /></view>
				</view>
				<view class="flex justify-between inputitem">
					<view>支付宝账号</view>
					<view><input v-model="mobile" placeholder="请输入支付宝账号" /></view>
				</view>
				<view class="flex justify-center items-center btn-save">
					<button @tap.stop="save">立即设置</button>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	var that,App=getApp(),Comm=getApp().comm;
	export default {
		data() {
			return {
				user_id:'',
				realname:'',
				mobile:''
			}
		},
		onLoad() {
			that=this;
		},
		methods: {
			query(){
				if(!/^\d+$/.test(this.user_id)){
					uni.showToast({icon:'none',title:'推广员ID有误'});
					return;
				}
				this.comm.http('/api/tool/queryuserali',{user_id:this.user_id}).then(res=>{
					if(res.code==0){
						uni.showToast({icon:'none',title:res.msg});
						return;
					}else{
						that.realname=res.data.realname;
						that.mobile=res.data.mobile;
					}
				});
			},
			save(){
				if(!/^\d+$/.test(this.user_id)){
					uni.showToast({icon:'none',title:'推广员ID有误'});
					return;
				}
				if(!/^[\u4e00-\u9fa5]{2,}$/.test(this.realname)){
					uni.showToast({icon:'none',title:'姓名有误'});
					return;		
				}
				if(!/(^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$)|(^\d{11}$)/.test(this.mobile)){
					uni.showToast({icon:'none',title:'账号为邮箱或手机'});
					return;
				}
				
				this.comm.http('/api/tool/setuserali',{user_id:this.user_id,realname:this.realname,mobile:this.mobile}).then(res=>{
					uni.showToast({icon:'none',title:res.msg});
				});
			}
		}
	}
</script>

<style lang="scss">
	.setpidpage{
		.inputitem{
			align-items: center;
			view:nth-child(2){
				flex: 1;margin-left: 8px;
				input{
					height:40px; width: 100%; border-bottom: 1px solid #f0f0f0; font-size: 13px;
				
				}
			}

		}
		.tips{
			font-size: 12px; color: #999; padding: 8px 0; display: block;
		}
	}
</style>
